class Admin::CommunitiesController < Admin::AdminApplicationController
 layout "admin"
 before_filter :admin_login_required
 
 def show
   @community = Community.find(params[:id])
 end
 
 def new
   @district = District.find(params[:district_id])
   @community = Community.new(params[:community])
 end
 
 def create
    @district = District.find(params[:district_id])
    @community = Community.new(params[:community])
    @community.district_id = @district.id
    @community.created_user_id = current_user.id
    if @community.save
      @forum = Forum.new
      @forum.community_id = @community.id
      @forum.save!
      redirect_to admin_communities_url(@community.district, @community)
    else
      render :action => 'new', :id => @district
    end
 end
 
  def edit
    @community = Community.find(params[:id])
  end
  
  def update
    @community = Community.find(params[:id])
    if @community.update_attributes(params[:community])
      redirect_to admin_communities_url(@community.district, @community)
    else
      render :action => 'edit', :id => @community
    end
  end
end
